package fr.norsys.mapper.console.web;

import uk.ltd.getahead.dwr.ExecutionContext;
import fr.norsys.mapper.console.model.Application;
import fr.norsys.mapper.console.model.Connection;
import fr.norsys.mapper.console.model.ConsoleCst;
import fr.norsys.mapper.console.model.Resource;
import fr.norsys.mapper.console.service.ApplicationService;
import fr.norsys.mapper.console.service.ValidationHelper;
import fr.norsys.mapper.console.utils.PasswordEncoder;

public class ValidationHelperDWR {
	private ValidationHelper validationHelper;

	private ApplicationService applicationService;

	public ValidationHelper getValidationHelper() {
		return validationHelper;
	}

	public void setValidationHelper(ValidationHelper validationHelper) {
		this.validationHelper = validationHelper;
	}

	public boolean isConnectionValid(Connection connection) {
		return validationHelper.isConnectionValid(connection);
	}

	public String isSearchResourceValid(Resource resource)  throws Exception {
		String result;
		Application curApplication = (Application) ExecutionContext.get()
				.getSession().getAttribute(ConsoleCst.CURRENT_APPLICATION);
		if (!validationHelper.isConnectionValid(curApplication.getConnection())) {
			result = ConsoleCst.CONNECTION_NOT_VALID;
		} else if (validationHelper.isSearchResourceValid(resource,
				curApplication.getConnection())) {
			result = ConsoleCst.RESOURCE_VALID;
		} else {
			result = ConsoleCst.RESOURCE_NOT_VALID;
		}
		return result;
	}

	public ApplicationService getApplicationService() {
		return applicationService;
	}

	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}
}
